package com.lottery.im.module.service.ui;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.view.View;
import butterknife.BindView;
import butterknife.OnClick;
import com.lottery.im.R;
import com.lottery.im.api.result.entity.UserInfo;
import com.lottery.im.base.BaseSwipeFragment;
import com.lottery.im.module.service.presenter.IntegralPresenter;
import com.lottery.im.module.service.view.IntegralView;
import com.lottery.im.view.DancingView;

@SuppressLint("ValidFragment") public class IntegralFragment
    extends BaseSwipeFragment<IntegralPresenter> implements IntegralView {

  @BindView(R.id.tv2) DancingView tv2;
  private double amount;
  private final static int REUQESTCODE=100;

  public IntegralFragment(double amount) {
    this.amount = amount;
  }

  @Override protected int getLayoutResId() {
    return R.layout.fragment_integral;
  }

  @Override protected void initPresenter() {
    presenter = new IntegralPresenter(getActivity(), this, this);
    presenter.init();
  }

  @Override public void initView() {
    tv2.setText(String.valueOf(amount));
  }

  @OnClick({ R.id.iv_back, R.id.tv_detail, R.id.btn_exchange })
  public void onViewClicked(View view) {
    switch (view.getId()) {
      case R.id.iv_back:
        popBackStack();
        break;
      case R.id.tv_detail:
        startFragment(new UserCashListFragment());
        break;
      case R.id.btn_exchange:
        startFragmentForResult(new CommodityGetLimitFragment(amount),REUQESTCODE);
        break;
    }
  }

  @Override protected void onFragmentResult(int requestCode, int resultCode, Intent data) {
    super.onFragmentResult(requestCode, resultCode, data);
    if(requestCode==requestCode&&resultCode==CommodityGetLimitFragment.RESULTCODE){
      presenter.queryUserCommonInfo();
    }
  }

  @Override public void loadUserCommonInfoSuccess(UserInfo userCommonMapBean) {
    tv2.setText(String.valueOf(userCommonMapBean.getAmount()));
    tv2.setDuration(amount= userCommonMapBean.getAmount());
    tv2.dance();
  }
}
